/// API配置
/// 定义应用中使用的所有API路径
library;

class ApiConfig {
  // 默认主机地址 - 使用可配置的地址
  static String hostUrl = 'localhost:3000'; // 使用localhost而非IP地址
  
  // 基础URL和Socket URL - 使用hostUrl变量
  static String get baseUrl => 'http://$hostUrl';
  static String get socketUrl => 'http://$hostUrl';
  
  // 配置为本地开发环境
  static void configureForLocalDevelopment() {
    hostUrl = 'localhost:3000';
    print('API配置已切换到本地开发环境: $hostUrl');
  }
  
  // 配置为局域网访问
  static void configureForLAN(String ip, [String port = '3000']) {
    hostUrl = '$ip:$port';
    print('API配置已切换到局域网环境: $hostUrl');
  }
  
  // 配置为Web平台访问
  static void configureForWeb(String ip, [String port = '3000']) {
    hostUrl = '$ip:$port';
    print('API配置已切换到Web平台环境: $hostUrl');
  }
  
  // 认证API
  static String get loginUrl => '$baseUrl/api/auth/login';
  static String get registerUrl => '$baseUrl/api/auth/register';
  static String get logoutUrl => '$baseUrl/api/auth/logout';
  static String get verifyTokenUrl => '$baseUrl/api/auth/verify';
  static String get currentUserUrl => '$baseUrl/api/auth/me';
  
  // 用户API
  static String get userProfileUrl => '$baseUrl/api/users/profile';
  static String get uploadAvatarUrl => '$baseUrl/api/users/avatar';
  static String get searchUsersUrl => '$baseUrl/api/users/search';
  
  // 联系人API
  static String get contactsUrl => '$baseUrl/api/contacts';
  static String get addContactUrl => '$baseUrl/api/contacts/add';
  
  // 消息API
  static String get messagesUrl => '$baseUrl/api/messages';
  static String get uploadFileUrl => '$baseUrl/api/messages/upload';
  
  // 对话API
  static String get conversationsUrl => '$baseUrl/api/conversations';
  
  // 动态生成特定资源URL的方法
  static String userUrl(String userId) => '$baseUrl/api/users/$userId';
  static String contactUrl(String contactId) => '$baseUrl/api/contacts/$contactId';
  static String messageUrl(String messageId) => '$baseUrl/api/messages/$messageId';
  static String conversationUrl(String conversationId) => '$baseUrl/api/conversations/$conversationId';
  static String conversationMessagesUrl(String conversationId) => '$baseUrl/api/conversations/$conversationId/messages';
  static String markConversationReadUrl(String conversationId) => '$baseUrl/api/conversations/$conversationId/read';
} 